package cn.shop.humh.product.controller.user;

import cn.shop.humh.product.dao.dataobject.UserDO;
import cn.shop.humh.product.dao.mapper.UserMapper;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PackageName: cn.shop.humh.product.controller.user
 * @ClassName: UserController
 * @Description:
 * @author: hgx61
 * @date: 2024/7/10 11:50
 */

@RestController
@RequestMapping("/user")
public class UserController {

  @Autowired
  private UserMapper userMapper;

  @PostMapping("/add")
  public int addUser(@RequestBody UserDO user) {
    user.setCreateTime(new Date());
    userMapper.insert(user);
    return user.getId();
  }

  @GetMapping("/get")
  public UserDO getUserById(Integer id) {
    return userMapper.selectById(id);
  }

  @GetMapping("/getByUsername")
  public UserDO getUserByUsername(String username) {
    return userMapper.selectByUsername(username);
  }

  @GetMapping("/getByIds")
  public List<UserDO> getUserByIds(@RequestBody Collection<Integer> ids) {
    return userMapper.selectByIds(ids);
  }

}
